package com.example.liuke.guangguang.videopicwebview;

import android.content.Context;
import android.media.MediaPlayer;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.example.liuke.guangguang.R;
import com.example.liuke.guangguang.ui.CustomerVideoView;
import com.example.liuke.guangguang.ui.SliderControl;

/**
 * Created by liuke on 2017/11/7.
 */

public class WebVideoSliderView extends BaseSliderView {

    private WebVideoView webVideoView;
    private String url;
    private  Context context;
    private SliderControl slidlistener;

    public  void  setWebVideoSliderView(SliderControl sliderControl){
        slidlistener=sliderControl;
    }
    public WebVideoSliderView(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public View getView() {
       /* View v = LayoutInflater.from(getContext()).inflate(R.layout.view_web_video_slider, null);
        webVideoView = (WebVideoView) v.findViewById(R.id.web_video_view);
        webVideoView.loadUrl(url);*/
        View v = LayoutInflater.from(getContext()).inflate(R.layout.video, null);
        CustomerVideoView videoView = (CustomerVideoView)v.findViewById(R.id.myvideo);
        videoView.setVideoPath(url);
        //设置视频控制器
        //videoView.setMediaController(new MediaController(context));
        videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                return true;
            }
        });
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                //slidlistener.start();
            }
        });
        videoView.setPlayPauseListener(new CustomerVideoView.PlayPauseListener() {
            @Override
            public void onPlay() {
                slidlistener.stop();
            }

            @Override
            public void onPause() {

            }
        });
        //slidlistener.start(videoView);
        //videoView.start();
        Toast.makeText(context,"llll",Toast.LENGTH_SHORT).show();
        return v;
    }

    public void loadUrl(String url) {
        this.url = url;
    }
}